package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseOneDAO;
import canglang.monitor.cases.model.CaseOneModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseOneMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchOneTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

@SuppressWarnings("unchecked")
public class CaseOneMgrImpl implements CaseOneMgr {

    private CaseLightMgr caseLightMgr;

    private CaseOneDAO caseOneDAO;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

    public void setCaseOneDAO(CaseOneDAO caseOneDAO) {
        this.caseOneDAO = caseOneDAO;
    }

    public CaseOneModel addCaseOne(CaseOneModel caseOneModel) {
        int id = caseOneDAO.addCaseOne(caseOneModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("01");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseOneModel.getDeptId());
        caseLightModel.setPplInd("N");
        caseLightModel.setProcInd("N");
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseOneModel.getCreateId());
        caseLightModel.setUpdateId(caseOneModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
        return caseOneDAO.getCaseOne(id);
    }

    public CaseOneModel getCaseOne(int caseOneId) {
        return caseOneDAO.getCaseOne(caseOneId);
    }

    public CaseOneModel saveCaseOne(CaseOneModel caseOneModel) {
        caseOneDAO.saveCaseOne(caseOneModel);
        caseLightMgr.updateLightDept("01",caseOneModel.getCaseOneId(),caseOneModel.getDeptId());
        return caseOneDAO.getCaseOne(caseOneModel.getCaseOneId());
    }

    public void deleteCaseOne(int caseOneId) {
        caseLightMgr.deleteUnuseLight("01",caseOneId);
        caseOneDAO.deleteCaseOne(caseOneId);

    }

    public PaginatedListHelper search(PaginatedListHelper helper, SearchOneTO searchTO) {
        int count = caseOneDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseOneDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

    public List getCaseOneList(SearchOneTO searchTO) {
        return caseOneDAO.getCaseOneList(searchTO);
    }

     public Integer getCaseOneReportList(SearchOneTO searchTO) {
        return caseOneDAO.getCaseOneReportList(searchTO);
    }
}
